package cz.cizek.tutorials.designpatterns.simplefactorymethod;

/**
 * @author jcizek
 */
public abstract class Person {

    private static int index = 0;

    //------------------------------------------------FACTORY METHOD----------------------------------------------------
    public static Person getRandomPerson() {
        switch (index++ % 2) {
            case 0:
                return new LazyPerson();
            case 1:
                return new EagerPerson();
            default:
                throw new RuntimeException("Error in switch statement, some case is not catch");
        }
    }

    //------------------------------------------------PUBLIC METHODS----------------------------------------------------
    public abstract void wakeUp();

    public abstract void goWork();

    public abstract void goSleep();

    //-----------------------------------------------PRIVATE CLASSES----------------------------------------------------
    private static class LazyPerson extends Person {

        @Override
        public void wakeUp() {
            System.out.println("getting up");
        }

        @Override
        public void goWork() {
            System.out.println("working");
        }

        @Override
        public void goSleep() {
            System.out.println("still working");
        }
    }

    private static class EagerPerson extends Person {

        @Override
        public void wakeUp() {
            System.out.println("still sleep");
        }

        @Override
        public void goWork() {
            System.out.println("lazy working");
        }

        @Override
        public void goSleep() {
            System.out.println("sleep");
        }
    }
}


